/**
 * @Description: 便雅悯后台侧边栏
 * @Author: kanglin
 * @date: 2017/8/21
 * @Copyright: Created by Panxsoft.
 */


new Vue({
    el: '#admin_side_menu',

    data: function () {
        return {
            menus: []
        }
    },

    methods: {

        fetchUserInfo: function () {
            var self = this;
            this.$http.get(API_LIST.REMIND_CREATE).then(function(response){
                if( response.data.code !== 0 ){
                    throw Error('请求侧边栏数据错误,code:',response.data.code);
                }else{
                    self.menus = response.data.menus;
                }
            }).catch(function (error) {
                console.error(error.message);
            });
        },

        isActive: function (menu) {
            menu.sub_menus.forEach(function (sub_menu) {
                if( location.href === sub_menu.url ){
                   return true;
                }
            });
            return false;
        },

        isSubmenuActive: function (url) {
            return !!(url === location.href);
        },

    },


    mounted: function () {
        this.fetchUserInfo();
        console.dir(this.menus);
        window.__test = this;
    }

});